package com.sunny.design.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Sunny
 * @date 2020/3/7
 */
public class Element extends Document {

    private List<Document> documents = new ArrayList<>();

    protected Element(String name, int level) {
        super(name, level);
    }

    @Override
    public String getName() {
        return this.name;
    }

    public void addElement(Document document) {
        documents.add(document);
    }

    public void removeElement(Document document) {
        documents.remove(document);
    }

    public void print() {
        System.out.println(this.getName());
        for (Document document : documents) {
            for (int i = 1; i < document.level; i++) {
                System.out.print("    ");
            }
            document.print();
        }
    }
}
